import json
import os
from pathlib import Path
from typing import Dict


def load_node_config(node_type: str) -> Dict:
    """
    加载节点类型配置
    返回示例:
    {
        "label": "API节点",
        "width": 120,
        "height": 80,
        "style": {
            "color": "#66CC99",
            "selected_color": "#FFA500",
            "border_width": 2
        },
        "ports": {
            "input": [{"name": "输入", "data_type": "any"}],
            "output": [{"name": "输出", "data_type": "any"}]
        }
    }
    """
    config_path = Path(__file__).parent / "node_types.json"

    try:
        with open(config_path, 'r', encoding='utf-8') as f:
            configs = json.load(f)
            return configs.get(node_type, _get_default_config())
    except Exception as e:
        print(f"Error loading node config: {str(e)}")
        return _get_default_config()


def _get_default_config() -> Dict:
    """获取默认节点配置"""
    return {
        "label": "未知节点",
        "width": 100,
        "height": 60,
        "style": {
            "color": "#CCCCCC",
            "selected_color": "#FFA500",
            "border_width": 1.5
        },
        "ports": {
            "input": [{"name": "输入", "data_type": "any"}],
            "output": [{"name": "输出", "data_type": "any"}]
        }
    }